/*
 * Authors: Filipe Ferraz Salgado  (filipesalgado@hotmail.com)
 *          Alexandre Albano       (aalbano@gmail.com)
 *          Instituto de Matemática e Estatística
 *          Universidade de São Paulo
 */

package br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1;
import java.util.List;

import br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.TagMagnitude;
import br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.TagMagnitudeVector;

public class Tags {

	private TagMagnitudeVector tagMagnitudeVector;

	public Tags(TagMagnitudeVector tmv) {
		this.tagMagnitudeVector = tmv;
	} 
	
	private TagMagnitudeVector getTagMagnitudeVector() {
		return this.tagMagnitudeVector;
	}
	
	public Tags adicionar(Tags tagsNovas) {
		TagMagnitudeVector tmv = tagsNovas.getTagMagnitudeVector();
		this.tagMagnitudeVector = this.tagMagnitudeVector.add(tmv);
		
		return this;
	}
	
	public Tags atualizar(Tags tagsVelhas, Tags tagsNovas) {
		this.tagMagnitudeVector = this.tagMagnitudeVector.remove(tagsVelhas.getTagMagnitudeVector());
		this.tagMagnitudeVector = this.tagMagnitudeVector.add(tagsNovas.getTagMagnitudeVector()); 
		
		return this;
	}
	
	public Tags remover(Tags tagsVelhas) {
		this.tagMagnitudeVector = this.tagMagnitudeVector.remove(tagsVelhas.getTagMagnitudeVector());	
		
		return this;
	}
	
	@Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        List<TagMagnitude> sortedList = this.tagMagnitudeVector.getTagMagnitudes();
        double sumSqd = 0.;
        for (TagMagnitude tm: sortedList) {
            sb.append(tm);
            sumSqd += tm.getMagnitude()*tm.getMagnitude();
        }
       // sb.append("\nSumSqd = " + sumSqd);
        return sb.toString();
    }
}
